import Taro, { base64ToArrayBuffer, request } from '@tarojs/taro'
import Proxy from './proxy'//?
import { getStorage } from '../pages/components/utils'
import Utils from '../utils/index'

const storage = getStorage()

let RootUrl
if (process.env.TARO_ENV === 'h5') {
    const host = window.location.host;

    const protocol = window.location.protocol;
    RootUrl = protocol + "//" + host;
}

export const requestSystemUrl = (sysId) => {
    return new Promise((resolve, reject) => {
        Taro.request({
            url: API_CampusRoot + '/school/getSubsystemBySystemId',
            data: {
                schoolId: Utils.getQueryVariable('schoolId'),
                systemId: sysId
            }
        }).then((result) => {
            if (result?.data.url) {
                resolve(result?.data.url)
            } else {
                reject('请求出错')
            }
        })
    })
}

export const getBaseUrl = () => {
    let BASE_URL = ""
    if (process.env.NODE_ENV === "development") {
        console.log(654321)
        if (process.env.TARO_ENV === 'weapp') {
            //开发环境 - 根据请求不同返回不同的BASE_URL
            BASE_URL = window.baseUrl

        } else {
            if (Utils.getQueryVariable('env') === 'weapp') {
                BASE_URL = window.baseUrl
            } else {
                // BASE_URL = "http://192.168.129.115:10329/notice/";
                // BASE_URL = "http://iscb.lancooedu.com/office-platform/";
                // BASE_URL = "https://xdtest.aiedu100.com/office-platform/";
                BASE_URL = "http://192.168.129.115:8071/office-platform/"
                // BASE_URL = "http://isca.lancooedu.com/office-platform/";
            }
            // BASE_URL = 'http://192.168.122.124:22106/Web_PersonalCenter/'
            // BASE_URL = 'http://218.75.78.194:10101/Web_PersonalCenter'
        }
    } else {
        console.log(1234567)
        if (process.env.TARO_ENV === 'weapp') {
            BASE_URL = window.baseUrl
        } else {
            if (Utils.getQueryVariable('env') === 'weapp') {
                BASE_URL = window.baseUrl
            } else {
                BASE_URL = RootUrl + '/office-platform/';
            }
        }
    }

    // console.log('baseUrl', BASE_URL)

    return BASE_URL;
};

// export const API_TransmitUrl = 'http://192.168.129.172:50000';

export const API_TransmitUrl = 'https://campus.lancooedu.com:50000'; //转发访问接口

export const API_CampusRoot = 'https://campus.lancooedu.com'